/**
 * @author roua_troua
 */
package q10.GUI;
import java.awt.Component;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JOptionPane;
import q10.ArboriFunctionali;

public class SubmitAction extends AbstractAction{
	private ArboriFunctionali a;
	private static final long serialVersionUID = 1L;
	private Component target;
	private String functie;
   
	public SubmitAction(String name, Icon icon, Component t){
	       putValue(Action.NAME, name);
	       putValue(Action.SMALL_ICON, icon);
	       putValue(Action.SHORT_DESCRIPTION, name + " the program");
	       target = t;	       
	    }
	
	public SubmitAction(String name, Icon icon, Component t,String jt){
       putValue(Action.NAME, name);
       putValue(Action.SMALL_ICON, icon);
       putValue(Action.SHORT_DESCRIPTION, name + " the program");
       target = t;
       functie = jt;
       System.out.println(functie);
    }
	
	public void setString(String s){
		functie = s;
	}
	
   public void actionPerformed(ActionEvent evt) {
	   functie = GUITemplate.jtFunctie.getText();
	   
	   if(getValue(Action.NAME).equals("Parsare")){
		   JOptionPane.showMessageDialog(target, "Parsare functie");		   
		   		   
		   System.out.println(functie);
		   Command c = new Parsare(a,functie);
           a = c.execute();

	   }		   
	   else if(getValue(Action.NAME).equals("Derivata")){
		   JOptionPane.showMessageDialog(target, "Der");
	   		
	   	   a.getRadacina().setX(0);
	   	   //Command cf = new CalculField(a,jtFunctie);
	   	   //cf.execute();
	   	   Command df = new DerivareField(a,GUITemplate.jtFunctie);
	   	   df.execute();
	   	   //Command dcf = new DerivareCalculField(a,fdx0);
	   	   //dcf.execute(); 
	   }
	   
	   if(getValue(Action.NAME).equals("Val.deriv.")){
		   Command cf = new CalculField(a,GUITemplate.jtFunctie);
	   	   cf.execute();
	   }
   }
   
} 